package com.itheima.demo;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo_HashMap {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("1号丈夫", "1号妻子");
        map.put("2号丈夫", "2号妻子");
        map.put("3号丈夫", "3号妻子");
        map.put("4号丈夫", "4号妻子");
        map.put("5号丈夫", "5号妻子");
        //第一种方式遍历;
        Set<String> keys = map.keySet();
        for (String key : keys) {
            String value = map.get(key);
            System.out.println(key + " = " + value);
        }
        System.out.println("=====================");

        //第二种方式遍历;
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + " = " + value);
        }
        System.out.println("=====================");

        //第三种方式遍历;
        map.forEach((key, value) -> System.out.println(key + " = " + value));
    }
}
